<?php
class Ecore_Upload_Product {		
	public static function upload($file)
	{
		if ($file['name'] != '') {
			$strFolder			= date('Y/m/d/');
			$strFullFolder 		= DIR_PRODUCT_FULL . $strFolder;
			$strThumbFolder 	= DIR_PRODUCT_THUMB . $strFolder;				
			$strSmallFolder 	= DIR_PRODUCT_SMALL . $strFolder;				
			$arrUploadResult 	= Ecore_Upload_Common::process($file, $strFullFolder, IMAGE_SIZE*1024*1024);			
			if ($arrUploadResult['error'] == 0) {
				$arrUploadResult['path']	= $strFolder . $arrUploadResult['name'];
				$strFullPath 				= $arrUploadResult['fullpath'];				
				$strFileName				= $arrUploadResult['name'];
				$strThumbPath				= $strThumbFolder . $strFileName;				
				$strSmallPath				= $strSmallFolder . $strFileName;				
				$objThumb 					= new Ecore_Thumbnail($strFullPath);				
				if ($arrUploadResult['width'] > IMAGE_FULL_WIDTH) {
					$objThumb->quality 		  	= 100;
					$objThumb->output_format 	= 'JPG,JPEG,jpg,jpeg,GIF,gif,PNG,png';
					$objThumb->jpeg_progressive = 1;
					$objThumb->bicubic_resample = false;
					$objThumb->allow_enlarge	= false;
					$objThumb->size_width(IMAGE_FULL_WIDTH);
					$objThumb->process();
					$objThumb->save($strFullPath);					
				}	
				//thumb 
				Ecore_Function::mkDirectory($strThumbFolder);
				Ecore_Upload_Common::thumbImg($strFullPath, $strThumbPath, IMAGE_THUMB_WIDTH);
				//square
				Ecore_Function::mkDirectory($strSmallFolder);
				Ecore_Crop::square($strFullPath, $strSmallPath, IMAGE_SMALL_WIDTH, IMAGE_SMALL_HEIGHT);
				return $arrUploadResult;				
			}
			return $arrUploadResult;
		}
		return null;
	}
}
?>
